#ifndef STACKTP_H_
#define STACKTP_H_

template <class T>
class Stack
{
private:
    enum {MAX = 10};
    T *items_;
    int size_;
    int top_;
public:
    explicit Stack(int ss=MAX) ;
    Stack(const Stack &st);
    ~Stack(){delete[] items_;}
    bool isempty() const { return top_ == 0; }
    bool isfull() const {return top_ == size_; }
    int size() const {return size_;}
    int top() const {return top_;}
    void show() const {std::cout << "Stack["<< this <<"] on " << top_ <<" in max "<<size_<< std::endl;}
    bool push(const T &item); // add
    bool pop(T &item); // remove,pop to item
    Stack & operator=(const Stack &st);
};
template<class T>
Stack<T>::Stack(int ss) : size_(ss), top_(0)
{
    items_ = new T[size_];
}

template<class T>
Stack<T>::Stack(const Stack &st)
{
    size_ = st.size_;
    top_ = st.top_;
    items_ = new T[size_];
    for (int i = 0; i < top_; ++i)
        items_[i] = st.items_[i];
}

template<class T>
bool Stack<T>::push(const T &item) // add
{
    if(top_ >= size_)
        return false;
    else{
        items_[top_]=item;
        top_++;
        return true;
    }
}

template<class T>
bool Stack<T>::pop(T &item) // add
{
    if(top_ <= 0)
        return false;
    else{
        top_--;
        item = items_[top_];
        return true;
    }
}
template<class T>
Stack<T> & Stack<T>::operator=(const Stack<T> &st)
{
    if (this == &st)
        return *this;
    delete [] items_;
    size_ = st.size_;
    top_ = st.top_;
    items_ = new T[size_];
    for (int i = 0; i < top_; ++i)
        items_[i] = st.items_[i];
    return *this;
}
#endif


